/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package dreamwar.view;

import dreamwar.controller.GUIController;
import java.awt.CardLayout;
import java.awt.Dimension;

/**
 *
 * @author Berto_Romero
 */
public class MainFrame extends javax.swing.JFrame {

    /**
     * Creates new form MainJFrame
     */
    public MainFrame() {
        initComponents();
        mainPanel.setPreferredSize(armyListPanel.getPreferredSize());
        mainPanel.revalidate();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainScrollPane = new javax.swing.JScrollPane();
        mainPanel = new javax.swing.JPanel();
        armyListPanel = new dreamwar.view.ArmyListPanel();
        createArmyPanel = new dreamwar.view.CreateArmyPanel();
        modifyArmyPanel = new dreamwar.view.ModifyArmyPanel();
        featureListPanel = new dreamwar.view.FeatureListPanel();
        createFeaturePanel = new dreamwar.view.CreateFeaturePanel();
        modifyFeaturePanel = new dreamwar.view.ModifyFeaturePanel();
        weaponListJPanel1 = new dreamwar.view.WeaponListPanel();
        menuBar = new javax.swing.JMenuBar();
        armyMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        unitMenu = new javax.swing.JMenu();
        armiesMenuItem = new javax.swing.JMenuItem();
        featuresMenuItem = new javax.swing.JMenuItem();
        weaponsMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        mainScrollPane.setBorder(null);
        mainScrollPane.setPreferredSize(new java.awt.Dimension(640, 480));

        mainPanel.setAutoscrolls(true);
        mainPanel.setLayout(new java.awt.CardLayout());
        mainPanel.add(armyListPanel, "armyListPanel");
        mainPanel.add(createArmyPanel, "createArmyPanel");
        mainPanel.add(modifyArmyPanel, "modifyArmyPanel");
        mainPanel.add(featureListPanel, "featureListPanel");
        mainPanel.add(createFeaturePanel, "createFeaturePanel");
        mainPanel.add(modifyFeaturePanel, "modifyFeaturePanel");
        mainPanel.add(weaponListJPanel1, "card4");

        mainScrollPane.setViewportView(mainPanel);
        mainPanel.getAccessibleContext().setAccessibleName("");
        mainPanel.getAccessibleContext().setAccessibleDescription("");

        armyMenu.setText("Archivo");

        jMenuItem1.setText("Nuevo");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        armyMenu.add(jMenuItem1);

        menuBar.add(armyMenu);

        unitMenu.setText("Ver");

        armiesMenuItem.setText("Ejércitos");
        armiesMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                armiesMenuItemActionPerformed(evt);
            }
        });
        unitMenu.add(armiesMenuItem);

        featuresMenuItem.setText("Rasgos");
        featuresMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                featuresMenuItemActionPerformed(evt);
            }
        });
        unitMenu.add(featuresMenuItem);

        weaponsMenuItem.setText("Armas");
        weaponsMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                weaponsMenuItemActionPerformed(evt);
            }
        });
        unitMenu.add(weaponsMenuItem);

        menuBar.add(unitMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addComponent(mainScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(0, 0, 0))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void armiesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_armiesMenuItemActionPerformed
        changeCard(GUIController.ARMY_LIST_PANEL);
    }//GEN-LAST:event_armiesMenuItemActionPerformed

    private void weaponsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_weaponsMenuItemActionPerformed
        changeCard("card4");
    }//GEN-LAST:event_weaponsMenuItemActionPerformed

    private void featuresMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_featuresMenuItemActionPerformed
        changeCard(GUIController.FEATURE_LIST_PANEL);
    }//GEN-LAST:event_featuresMenuItemActionPerformed

    public void changeCard(String cardName) {
        CardLayout cl = (CardLayout) (mainPanel.getLayout());
        cl.show(mainPanel, cardName);
        Dimension dimension = mainPanel.getPreferredSize();
        switch (cardName) {
            case GUIController.ARMY_LIST_PANEL:
                dimension = armyListPanel.getPreferredSize();
                break;
            case GUIController.CREATE_ARMY_PANEL:
                dimension = createArmyPanel.getPreferredSize();
                break;
            case GUIController.MODIFY_ARMY_PANEL:
                dimension = modifyArmyPanel.getPreferredSize();
                break;
        }
        mainPanel.setPreferredSize(dimension);
        mainPanel.revalidate();
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Windows (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    //break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                MainFrame mainFrame = new MainFrame();
                GUIController.getInstance().setMainFrame(mainFrame);
                GUIController.getInstance().setArmyListPanel(mainFrame.armyListPanel);
                GUIController.getInstance().setModifyArmyPanel(mainFrame.modifyArmyPanel);
                mainFrame.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem armiesMenuItem;
    private dreamwar.view.ArmyListPanel armyListPanel;
    private javax.swing.JMenu armyMenu;
    private dreamwar.view.CreateArmyPanel createArmyPanel;
    private dreamwar.view.CreateFeaturePanel createFeaturePanel;
    private dreamwar.view.FeatureListPanel featureListPanel;
    private javax.swing.JMenuItem featuresMenuItem;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JScrollPane mainScrollPane;
    private javax.swing.JMenuBar menuBar;
    private dreamwar.view.ModifyArmyPanel modifyArmyPanel;
    private dreamwar.view.ModifyFeaturePanel modifyFeaturePanel;
    private javax.swing.JMenu unitMenu;
    private dreamwar.view.WeaponListPanel weaponListJPanel1;
    private javax.swing.JMenuItem weaponsMenuItem;
    // End of variables declaration//GEN-END:variables
}
